import java.util.*;


//   class ListNode {
//    int val;
//    ListNode next = null;
//    public ListNode(int val) {
//      this.val = val;
//    }
//  }


public class Solution3 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param head ListNode类 
     * @return ListNode类
     */
    public static ListNode oddEvenList (ListNode head) {
        // write code here
        ListNode dum = new ListNode(0);
        ListNode cur = dum;
        ListNode c = new ListNode(0);
        ListNode cur1 = c;
        while(head != null) {
            if(head.val % 2 != 0) {
                cur.next = head;
                cur = cur.next;
            } else {
                cur1.next = head;
                cur1 = cur1.next;
            }
            head = head.next;
        }
        cur.next = c.next;
        return dum.next;
    }

    public static void main(String[] args) {
        ListNode head = new ListNode(2);
        head.next = new ListNode(1);
        head.next.next = new ListNode(3);
        head.next.next.next = new ListNode(5);
        head.next.next.next.next = new ListNode(6);
        head.next.next.next.next.next = new ListNode(4);
        head.next.next.next.next.next.next = new ListNode(7);
        oddEvenList(head);

    }
}